import { Component, OnInit } from '@angular/core';

import { BlogArticleCard } from '../../class/blog-article-card';
import { BlogService } from '../../service/blog.service';

@Component({
  selector: 'app-blog-list',
  templateUrl: './blog-list.component.html',
  styleUrls: ['./blog-list.component.css']
})
export class BlogListComponent implements OnInit {
  // 博客列表
  blogArticleCards: BlogArticleCard[];
  // 当前页数
  currentPage: number = 1;
  // 每页条数
  pageSize: number = 10;
  // 搜索关键字
  search: string = "";

  constructor(private blogService: BlogService) { }

  ngOnInit() {
    this.getBlogArticleCards(this.currentPage, this.pageSize, this.search);
  }

  private getBlogArticleCards(currentPage: number, pageSize: number, search: string) {
    let bindThis = this;
    bindThis.blogService.queryArticlesByPage(currentPage, pageSize, search, (result) => {
        bindThis.blogArticleCards = result.data.pageData;
    });
  }

  private refreshBlogList() {
    this.getBlogArticleCards(this.currentPage, this.pageSize, this.search);
  }
}
